﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Rhino.Mocks;
using EnvDTE80;
using TSVNAddin.VS;
using EnvDTE;

namespace TSVNAddinUtils.Test
{
	[TestFixture]
	public class RemoveBarCommandFixture
	{
		[Test]
		public void Exec()
		{
			var menuBarAdapter = MockRepository.GenerateMock<IMainBarAdapter>();
			menuBarAdapter.Expect(x => x.RemoveTortoiseCommandBar());

			var toolBarAdapter = MockRepository.GenerateMock<IMainBarAdapter>();
			toolBarAdapter.Expect(x => x.RemoveTortoiseCommandBar());

			var solutionBar = MockRepository.GenerateMock<IMainBarAdapter>();
			solutionBar.Expect(x => x.RemoveTortoiseCommandBar());

			DTEAdapter dte = MockRepository.GenerateMock<DTEAdapter>((DTE2)null);
			dte.Expect(x => x.GetMenuBar()).Return(menuBarAdapter);
			dte.Expect(x => x.GetToolBar()).Return(toolBarAdapter);
			dte.Expect(x => x.GetSolutionBar()).Return(solutionBar);
			dte.Expect(x => x.Quit());

			DTEInstanceCreator ic = MockRepository.GenerateMock<DTEInstanceCreator>("");
			ic.Expect(x => x.CreateInstance()).Return(dte);

			RemoveBarCommand command = new RemoveBarCommand(ic);
			command.Exec(new string[0]);

			dte.VerifyAllExpectations();
			ic.VerifyAllExpectations();
			menuBarAdapter.VerifyAllExpectations();
			toolBarAdapter.VerifyAllExpectations();
			solutionBar.VerifyAllExpectations();
		}

		[Test]
		public void ExecCloseDteWhenExceptionOccured()
		{
			var menuBarAdapter = MockRepository.GenerateMock<IMainBarAdapter>();
			menuBarAdapter.Expect(x => x.RemoveTortoiseCommandBar()).Throw(new Exception());

			DTEAdapter dte = MockRepository.GenerateMock<DTEAdapter>((DTE2)null);
			dte.Expect(x => x.GetMenuBar()).Return(menuBarAdapter);
			dte.Expect(x => x.Quit());

			DTEInstanceCreator ic = MockRepository.GenerateMock<DTEInstanceCreator>("");
			ic.Expect(x => x.CreateInstance()).Return(dte);

			RemoveBarCommand command = new RemoveBarCommand(ic);
			command.Exec(new string[0]);

			dte.VerifyAllExpectations();
		}
	}
}
